<template>
  <div>
    <div class="header_search_nav search_form">
      <div class="ipt_left">
        <el-form ref="queryForm" :model="queryParams" label-width="80px">
          <el-row>
            <el-col :span="6">
              <el-form-item label="门店" prop="storeId">
                <el-select
                  v-model="queryParams.storeId"
                  placeholder="请选择"
                  @change="SelectUser"
                  filterable
                >
                  <el-option
                    v-for="(item, index) in $store.state.user.stores"
                    :key="index"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="5">
              <el-form-item prop="userId" label="人员名称">
                <el-select
                  v-model="queryParams.userId"
                  filterable
                  placeholder="请选择技师"
                >
                  <el-option
                    v-for="item in usersList"
                    :key="item.userId"
                    :label="item.nickname"
                    :value="item.userId"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <!-- {{ queryParams.date }} -->
              <div class="timebox">
                <el-form-item label="日期时间" prop="date">
                  <timer
                    ref="timer"
                    :timer.sync="queryParams.date"
                    @query="handleQuery"
                    :flag="'T'"
                    :isCheck="isCheck"
                  ></timer>
                </el-form-item>
              </div>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <div class="btn_right">
        <button class="btn1" @click="handleQuery">筛选</button>
        <button class="btn2" @click="resetQuery">重置</button>
      </div>
    </div>

    <div class="table_card">
      <!-- 上部分 title -->
      <div class="table_card_top">
        <span class="solid_left1"></span>
        <div class="table_card_title">充卡业绩明细</div>
        <!-- <div class="op_right">
            <el-button
              @click="handleExport"
              :loading="exportLoading"
              class="repeat"
              v-hasPermi="['order:total:daily:paper:exl']"
              >导出</el-button
            >
          </div> -->
      </div>

      <div class="table_list">
        <el-table
          :data="TodayReportList"
          stripe
          style="width: 100%"
          v-loading="loading"
        >
          <el-table-column prop="storeName" label="门店名称"> </el-table-column>
          <el-table-column prop="userName" label="人员名称"> </el-table-column>
          <el-table-column prop="customerName" label="客户名称" width="200px">
          </el-table-column>
          <el-table-column prop="cardNo" label="会员卡号" width="200px">
          </el-table-column>
          <el-table-column prop="statementPerMoney" label="业绩金额">
          </el-table-column>
          <el-table-column prop="chargingTime" label="记账时间">
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            width="450"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="handleCheckMember(scope.row)"
                >详情</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          :total="total"
          :page.sync="queryParams.pageNo"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>

      <client-info
        ref="clientInfo"
        @childEvent="handleChildEvent"
      ></client-info>
    </div>
  </div>
</template>

<script>
import { getRechargeCardInfo } from "@/api/bpm/report";
//   import { ExcleStoreTodayDaily } from "@/api/bpm/excle";
import { getStoreUser } from "@/api/bpm/handmade";
import timer from "@/components/getTime/timer";
import ClientInfo from "@/components/ClientInfo/clientInfo.vue";
export default {
  name: "Storeadmintodayreport",
  components: { timer, ClientInfo },
  data() {
    return {
      TodayReportList: [],
      loading: false,
      value: "",
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        userId: "",
        storeId: "",
        date: [],
        startTime: "",
        endTime: "",
      },
      total: 0,
      exportLoading: false,
      isCheck: false,
      usersList: [],
    };
  },

  mounted() {
    if (!!this.$route.query.storeId) {
      this.queryParams.storeId = this.$route.query.storeId;
      this.SelectUser();
    }
    if (!!this.$route.query.userId) {
      this.queryParams.userId = this.$route.query.userId;
    }
    if (!!this.$route.query.date) {
      console.log("时间", this.$route.query.date);
      this.queryParams.date = JSON.parse(this.$route.query.date);
    }
    if (
      !!this.$route.query.date ||
      !!this.$route.query.userId ||
      !!this.$route.query.storeId
    ) {
      this.getList();
    }
  },

  created() {
    if (!this.$route.query.date) {
      this.isCheck = true;
    }
  },

  methods: {
    handleChildEvent(dataFromChild) {
      // 接收子组件发送的事件并调用相应的方法
      this.handleQuery();
    },
    handleCheckMember(row) {
      let rowcache = JSON.parse(JSON.stringify(row));
      rowcache.id = rowcache.customerId;
      this.$refs.clientInfo.MemberUserInfo(rowcache);
    },
    SelectUser() {
      this.getUsers();
      this.queryParams.userId = "";
    },
    getUsers() {
      getStoreUser({
        filterUser: "N",
        storeId: this.queryParams.storeId,
      })
        .then((res) => {
          const { code, data } = res;
          if (code === 0) {
            this.usersList = data;
          }
        })
        .catch((err) => {});
    },
    //   handleExport() {
    //     this.$modal
    //       .confirm("是否确认导出报表数据?")
    //       .then(() => {
    //         this.exportLoading = true;
    //         let queryParams = JSON.parse(JSON.stringify(this.queryParams));

    //         console.log("1");
    //         if (!!this.queryParams.date) {
    //           queryParams.startTime = this.queryParams.date[0];
    //           queryParams.endTime = this.queryParams.date[1];
    //         }

    //         delete queryParams.date;

    //         console.log(queryParams)
    //         return ExcleStoreTodayDaily(queryParams);
    //       })
    //       .then((response) => {
    //         this.$download.excel(response, "门店日报表");
    //         this.exportLoading = false;
    //       })
    //       .catch(() => {
    //         this.exportLoading = false;
    //       });
    //   },

    // 筛选
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetFormData("queryForm");
      // this.queryParams.localDate = dayDataTime("obj").str;
      this.handleQuery();
    },

    // 表单重置
    resetFormData(formName) {
      console.log(this.$refs[formName]);
      this.$nextTick(() => {
        this.$refs[formName].resetFields();
      });
    },

    // 充卡业绩明细
    getList() {
      this.loading = true;
      const query = JSON.parse(JSON.stringify(this.queryParams));

      if (!!query.date) {
        query.startTime = this.queryParams.date[0];
        query.endTime = this.queryParams.date[1];
        query.date = [];
      }
      // console.log("query",query)
      getRechargeCardInfo(query)
        .then((res) => {
          console.log(res);
          this.loading = false;
          const { code, data } = res;
          if (code === 0) {
            this.TodayReportList = data.list;
            this.total = data.total;
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.solid_left1 {
  margin-left: 24px;
}
.goodTop {
  width: 100%;
  height: 48px;
  background: #ffffff;
  display: flex;
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.6);
  line-height: 48px;
  padding-left: 16px;
  .good_list {
    margin-right: 32px;
  }

  .good_active {
    color: #0052d9;
    border-bottom: 1px solid #0052d9;
  }
}

.w-200 {
  width: 200px;
  background: #ffffff;
  border-radius: 4px;
}

.client_name {
  font-size: 14px;
  font-weight: 400;
  color: #0052d9;
}

.give {
  height: 40px;
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
  margin-top: 40px;
  line-height: 40px;
}

.el-form-item {
  margin-bottom: 20px;
}

.recharge_form {
  padding: 10px 24px;
}

.memberName {
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
}
.el_row_item {
  margin-bottom: 10px;
}
.el_row_date {
  margin-top: 20px;
}
.el_row_reason {
  margin-top: 10px;
}

.el_row_date {
  .el-form-item {
    margin-bottom: 0px;
  }
}

.Order_box {
  display: flex;
  margin-left: -50px;
  .select_ipt {
    width: 130px;
    margin-right: 10px;
  }
}

.pay_ipt {
  margin-left: 50px;
}

.order_ipt {
  margin-left: -120px;
}

.timebox {
  margin-top: 10px;
}
</style>
